package com.innerClass;

import java.util.Arrays;
import java.util.Comparator;

public class InnerCode {

    private Inner1 inner1;
    private Inner2 inner2;
    public InnerCode() {
        this.inner1 = new Inner1();
        this.inner2 = new Inner2();
    }

    private int id;
    private static int age;
    public class Inner1{
        public void fun(){
            System.out.println("成员内部类" + id);
        }
    }
    public static class Inner2{
        private static int age2;
        public void fun(){
            System.out.println("静态内部类" + age);
        }
    }

    private Integer[] arr = {5,6,1};

    //局部内部类：有类名，仅限于此方法中使用
    public void fun1(){
        class A implements Comparator<Integer>{
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1 - o2;
            }
        }
        Arrays.sort(arr, new A());
    }

    //匿名内部类：不用知道类名
    public void method2(){
        final Comparator<Integer> b = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1 - o2;
            }
        };
        Arrays.sort(arr, b);
    }

    //lambda表达式：简化匿名内部类格式
    public void fun3() {
        Comparator<Integer> c = (Integer o1, Integer o2) -> o2 - o1;
        Arrays.sort(arr, c);
    }
}